package org.lonetree.tc.core;

import org.lonetree.tc.core.id.NumericalId;

/**
 * JAVADOC CourseComment
 *
 * @author xeon
 *
 */
public final class CourseComment extends Comment{
	
	public CourseComment(Course parentCourse, User user, String comment, boolean flagged){
		this(null, parentCourse, user, comment, flagged);
	}
	
	protected CourseComment(CourseCommentId courseCommentId, Course parentCourse, User user, String comment, boolean flagged){
		super(courseCommentId, parentCourse, user, comment, flagged);
		
		parentCourse.getComments().add(this);
	}
	
	/**
	 * JAVADOC CourseComment.getCourseCommentId()
	 *
	 * @return
	 */
	public CourseCommentId getCourseCommentId(){
		NumericalId id = getNumericalId();
		if(id instanceof TempId)
			return null;
		else
			return (CourseCommentId)getNumericalId();
	}
	
	protected void setCourseCommentId(CourseCommentId courseCommentId){
		setIdentifier(courseCommentId);
	}
	
	/**
	 * JAVADOC CourseComment.getParentCourse()
	 *
	 * @return
	 */
	public Course getParentCourse(){
		return (Course)getParentItem();
	}

	@Override
	protected String getIdentifierType(){
		return "courseCommentId";
	}
	
	/**
	 * JAVADOC CourseCommentId
	 *
	 * @author xeon
	 *
	 */
	public static class CourseCommentId extends NumericalId{

		/**
		 * JAVADOC CourseCommentId.CourseCommentId()
		 *
		 * @param numericalId
		 * @throws ValidationException
		 */
		public CourseCommentId(long numericalId) throws ValidationException{
			super(numericalId, INFINITE_LENGTH_ALLOWED);
		}
		
		/**
		 * JAVADOC CourseCommentId.CourseCommentId()
		 *
		 * @param numericalId
		 * @throws ValidationException
		 */
		public CourseCommentId(String numericalId) throws ValidationException{
			super(numericalId);
		}
		
		/**
		 * JAVADOC CourseCommentId.getCourseCommentIdLong()
		 *
		 * @return
		 */
		public Long getCourseCommentIdLong(){
			return getNumericalIdLong();
		}
	}
}
